//
//  SearchResultViewController.m
//  BaiTuan
//
//  Created by 看着太阳吃烧饼 on 15/12/31.
//  Copyright © 2015年 YR. All rights reserved.
//

#import "SearchResultViewController.h"
#import "SearchViewController.h"
@interface SearchResultViewController ()
@property (nonatomic, copy) UISearchBar *search;
@end

@implementation SearchResultViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self createView];
    self.view.backgroundColor = [UIColor redColor];
}

-(void)viewDidAppear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    _search.hidden = NO;
}

- (void)createView
{
    UIButton *backButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 25, 25)];
    [backButton addTarget:self action:@selector(popAction:) forControlEvents:UIControlEventTouchUpInside];
    [backButton setImage:[UIImage imageNamed:@"btn_backItem.png"] forState:UIControlStateNormal];
    [backButton setImage:[UIImage imageNamed:@"btn_backItem_highlighted.png"] forState:UIControlStateHighlighted];
    UIBarButtonItem *barButton = [[UIBarButtonItem alloc]initWithCustomView:(UIView *)backButton];
    self.navigationItem.leftBarButtonItem = barButton;
    
    _search = [[UISearchBar alloc]initWithFrame:CGRectMake(60, -10, kScreenWidth - 120, 64)];
    [self.navigationController.navigationBar addSubview:_search];
    _search.layer.cornerRadius = 10;
    _search.searchBarStyle = UISearchBarStyleMinimal;
    _search.delegate = self;
    _search.keyboardType = UIKeyboardTypeDefault;
    
//    SearchViewController *searchVC = [[SearchViewController alloc]init];
//    [searchVC setBlock:^(NSString *text)
//    {
//        _search.placeholder = text;
//    }];
    
}

- (void)popAction:(UIButton *)button
{
    
    [self.navigationController popViewControllerAnimated:YES];
    _search.hidden = YES;
    [_search resignFirstResponder];
}

#pragma mark - UISearchBarDelegate

- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
{
    [self popAction:nil];
    return YES;
}

@end
